<?php


namespace App\Models\Admin;


use App\Log\AdminTestItemLog;
use App\Log\DrugResidueProjectLog;

class DrugResidueProject extends Base
{
    const OPERATE_PID = 4;
    const MODEL = 'drug_residue_project';
    protected $table = 'drug_residue_project';
    protected $guarded = [];
    protected $dateFormat = 'U';

    public static function getList($data=[],$skip=0,$size=10)
    {
        $select=self::getWhere($data);
        $list=$select->orderBy('id','desc')
            ->select('id','name')
            ->skip($skip)->take($size)
            ->get();
        return $list;
    }

    public static function getWhere($data)
    {
        $select=self::where([]);
        if(isset($data['name']))
        {
            $select=$select->where('name','like','%'.$data['name'].'%');
        }
        return $select;
    }

    public static function getCount($data)
    {
        $select=self::getWhere($data);
        $count=$select->count();
        return $count;
    }

    public static function addLog($pre,$next,$type,$method='')
    {
        $info = AdminOperateModule::where('pid',self::OPERATE_PID)->where('type',$type)->where('model',self::MODEL)->when($method,function ($query)use ($method){
            $query->where('method',$method);
        })->first();
        if (!empty($info)){
            $adminLog = new DrugResidueProjectLog($pre,$next,$info);
            $adminLog->addLog();
        }
    }
}
